function [Ppp Pp] = PpfromKs(E,P,K,Kp,x,xp)

[U,~,V] = svd(E);
W = [0 -1 0; 1 0 0; 0 0 1];%define W rotation, page 277
Pp(:,:,1) = [U*W*V U(:,3)];Pp(:,:,2) = [U*W*V -U(:,3)];
Pp(:,:,3) = [U*W'*V U(:,3)];Pp(:,:,4) = [U*W'*V -U(:,3)];
%test a sample point
%do  i need to multiply by inv(K) to get the correct points?
%homogeneous 3D points using the distinct camera matrices
Xt(:,1) = findTriangulation(P,Pp(:,:,1),x,xp,K,Kp);
Xt(:,2) = findTriangulation(P,Pp(:,:,2),x,xp,K,Kp);
Xt(:,3) = findTriangulation(P,Pp(:,:,3),x,xp,K,Kp);
Xt(:,4) = findTriangulation(P,Pp(:,:,4),x,xp,K,Kp);
%depth pairs:
%First matrix P,P'1
xw = Pp(:,:,1)*Xt(:,1); w = 1/xw(3); depth2(1) = w/(Xt(4,1));
xw = P*Xt(:,1); w = 1/xw(3); depth1(1) = w/(Xt(4,1));
%Second matrix P,P'2
xw = Pp(:,:,2)*Xt(:,2); w = 1/xw(3); depth2(2) = w/(Xt(4,2));
xw = P*Xt(:,2); w = 1/xw(3); depth1(2) = w/(Xt(4,2));
%Third matrix P,P'3
xw = Pp(:,:,3)*Xt(:,3); w = 1/xw(3); depth2(3) = w/(Xt(4,3));
xw = P*Xt(:,3); w = 1/xw(3); depth1(3) = w/(Xt(4,3));
%Fourth matrix P,P'4
xw = Pp(:,:,4)*Xt(:,4); w = 1/xw(3); depth2(4) = w/(Xt(4,4));
xw = P*Xt(:,4); w = 1/xw(3); depth1(4) = w/(Xt(4,4));
%chech for which pair both depths are positive
a= find(depth2>0); b = find(depth1>0);
index = a==b;%gets the index 
Ppp = Pp(:,:,a(index));